package com.zking.ssm.controller;

import com.zking.ssm.model.HotelAssess;
import com.zking.ssm.service.IHotelAssessService;
import com.zking.ssm.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController//返回json格式的数据
@RequestMapping("/HotelAssess")//窄化路径
public class HotelAssessController {
    @Autowired
    private IHotelAssessService iHotelAssessService;

    @RequestMapping("/add")
    public Map<String,Object> add(HotelAssess hotelAssess){
        int n = iHotelAssessService.insert(hotelAssess);
        Map<String,Object> map = new HashMap<>();
        if(n >= 0){
            map.put("code",0);
            map.put("message","增加成功！");
        }else{
            map.put("code",-1);
            map.put("message","增加失败！");
        }
        return map;
    }
    @RequestMapping("/del")
    public Map<String,Object> del(HotelAssess hotelAssess){
        int n = iHotelAssessService.deleteByPrimaryKey(hotelAssess.getId());
        Map<String,Object> map = new HashMap<>();
        if(n >= 0){
            map.put("code",0);
            map.put("message","删除成功！");
        }else{
            map.put("code",-1);
            map.put("message","删除失败！");
        }
        return map;
    }

    @RequestMapping("/update")
    public Map<String,Object> update(HotelAssess hotelAssess){
        int n = iHotelAssessService.updateByPrimaryKeySelective(hotelAssess);
        Map<String,Object> map = new HashMap<>();
        if(n >= 0){
            map.put("code",0);
            map.put("message","修改成功！");
        }else{
            map.put("code",-1);
            map.put("message","修改失败！");
        }
        return map;
    }

    @RequestMapping("/get")
    public Map<String,Object> get(Integer id){
        HotelAssess idd = iHotelAssessService.selectByPrimaryKey(id);
        Map<String,Object> map = new HashMap<>();
        if(id != null){
            map.put("code",0);
            map.put("message","查询成功！");
            map.put("request",id);
        }else{
            map.put("code",-1);
            map.put("message","查询失败！");
        }
        return map;
    }
    @RequestMapping("/list")
    public Map<String,Object> list(HotelAssess hotelAssess){
        PageBean pageBean = new PageBean();
        List<HotelAssess> list= iHotelAssessService.SelectAll(hotelAssess,pageBean);
        Map<String,Object> map = new HashMap<>();
        if(list.size() >= 0){
            map.put("code",0);
            map.put("message","查询成功！");
            map.put("request",list);
        }else{
            map.put("code",-1);
            map.put("message","查询失败！");
        }
        return map;
    }
}
